package com.ebt.m.proposal_v2.utils;

import com.ebt.m.utils.ConfigData;
import com.ebt.m.commons.utils.Logger;

import java.util.Map;

/**
 * @author archer.qi
 *         Created on 2017/5/18.
 */
public class Utils {

    /**
     * 用于构建实体类的toString
     *
     * @param className
     * @param map
     * @return
     */
    public static String toString(String className, Map<String, Object> map) {
        if (ArrayUtils.isEmpty(map)) {
            return "";
        }
        StringBuilder builder = new StringBuilder();
        builder.append(" { " + "\n");
        for (Map.Entry<String, Object> m : map.entrySet()) {
            String key = m.getKey();
            String value = String.valueOf(m.getValue());
            builder.append(key + ": " + value + "\n");
        }
        builder.append(" } ");

        map.clear();
        map = null;

        return builder.toString();
    }

    /**
     * 用于构建实体类的toString
     *
     * @param map
     * @return
     */
    public static String toString(Map<String, Object> map) {
        if (ArrayUtils.isEmpty(map)) {
            return "";
        }
        StringBuilder builder = new StringBuilder();
        builder.append(" { " + "\n");
        for (Map.Entry<String, Object> m : map.entrySet()) {
            String key = m.getKey();
            String value = String.valueOf(m.getValue());
            builder.append(key + ": " + value + "\n");
        }
        builder.append(" } ");

        map.clear();
        map = null;

        return builder.toString();
    }

    public static void print(String msg) {
        if (ConfigData.DEBUG) {
            Logger.i(msg);
        }
    }

    public static void print(String tag, String msg) {
        if (ConfigData.DEBUG) {
            Logger.i(tag, msg);
        }
    }

}
